package org.hzero.order.app.service.impl;

import java.util.List;
import java.util.Map;

import org.hzero.boot.scheduler.infra.annotation.JobHandler;
import org.hzero.boot.scheduler.infra.enums.ReturnT;
import org.hzero.boot.scheduler.infra.handler.IJobHandler;
import org.hzero.boot.scheduler.infra.tool.SchedulerTool;
import org.hzero.mybatis.domian.Condition;
import org.hzero.order.domain.entity.Header;
import org.hzero.order.domain.repository.HeaderRepository;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author xiuiqng.Yang-Estelle-양수청
 * @date 2019/8/8 19:03
 */
@JobHandler("order-close")
public class JobService implements IJobHandler {

    @Autowired
    private HeaderRepository headerRepository;

    @Override
    public ReturnT execute(Map<String, String> map, SchedulerTool tool) {

        Condition condition = new Condition(Header.class);
        condition.createCriteria().andEqualTo("orderStatus", "SUBMITED");
        List<Header> headers = headerRepository.selectByCondition(condition);
        for (Header header : headers) {
            header.setOrderStatus("CLOSED");
        }

        headerRepository.batchUpdateOptional(headers, "orderStatus");

        return ReturnT.SUCCESS;
    }
}